package com.liu.susu.thread.task.async.async1;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @FileName AsyncTask1
 * @Description
 * @Author susu
 * @date 2022-03-09
 **/
@Slf4j
@Component
//@EnableAsync //@EnableAsync 注解放在异步任务类上，或者启动类上
public class AsyncTask2 {
    @Async
    public void doMyTask1() {
//        System.out.println("begin doMyTask1()-->"
//                + LocalDateTime.now()+"-->"+Thread.currentThread().getName());
        log.info(Thread.currentThread().getName()+"-->begin doMyTask1()...");

        long currentTimeMillis = System.currentTimeMillis();
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long currentTimeMillis1 = System.currentTimeMillis();

        log.info("end doMyTask1()-->doMyTask1任务耗时:"+(currentTimeMillis1-currentTimeMillis)+"ms");

    }

    @Async
    public void doMyTask2() {
        log.info(Thread.currentThread().getName()+"-->begin doMyTask2()...");

        long currentTimeMillis = System.currentTimeMillis();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long currentTimeMillis1 = System.currentTimeMillis();

        log.info("end doMyTask2()-->doMyTask2任务耗时:"+(currentTimeMillis1-currentTimeMillis)+"ms");
    }
    @Async
    public void doMyTask3() {
        log.info(Thread.currentThread().getName()+"-->begin doMyTask3()...");

        long currentTimeMillis = System.currentTimeMillis();
        try {
            Thread.sleep(1500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long currentTimeMillis1 = System.currentTimeMillis();

        log.info("end doMyTask3()-->doMyTask3任务耗时:"+(currentTimeMillis1-currentTimeMillis)+"ms");
    }

}
